
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
        <select name="" id="a">\
            <option value="请选择大小">请选择大小</option>
            <option value="大" >大</option>
            <option value="小" >小</option>
        </select>
        <br>
		 <img src="img2/1.jpg" id="obj">
		 <br>
		 <button type="button" onclick="a()">开始</button>
	</body>
	<script type="text/javascript">
		function a(){
            var select=document.getElementById('a');
            if(select.value=='请选择大小'){
                alert('请选择大小')
            }
            else if(select.value=='大'|| select.value=='小'){
                var num=0;
            var first= setInterval(
			   function(){
                var pic =document.getElementById('obj');
                var pc=b();
                console.log(pc)
                pic.src = "img2/" + pc + ".jpg";
                num++;
                if(num>10){
                    clearInterval(first);
                    c(pc)
                }
			   },100
            )
        }
       
            }
        
            
        function b(){
            while(true){
                var ran = Math.floor(Math.random()*7);
                if(ran!=0){
                    return ran;
                }
            }
        }
        function c(pc){
            var select=document.getElementById('a')
            if (select.value=='大') {
                if (pc>3) {
                    alert('你输了！');
                }else{
                    alert('你赢了');
                }
            }
            else if (select.value=='小') {
                if (pc<4) {
                    alert('你输了！');
                }else{
                    alert('你赢了');
                }
            }
        }
	</script>
</html>
